package com.example.demolib.config;

import com.example.demolib.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
// 注册配置拦截器
public class WebConfig implements WebMvcConfigurer {
    @Autowired
    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //     /book/** 表示拦截所有book下的所有路径
        // 不能拦截登录页面和前端页面
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/book/**")
                .excludePathPatterns("/book/login")
                .excludePathPatterns("/book/captcha")
                .excludePathPatterns("/css/**")
                .excludePathPatterns("/js/**")
                .excludePathPatterns("/**/*.html");
    }
}
